package com.example.moblie2021606143cwj0406;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tvMainTitle;
    private RadioGroup radGupCarType;
    private RadioButton radBtnMainSaloon;
    private RadioButton radBtnMainMPV;
    private RadioButton radBtnMainSUV;
    private RadioGroup radGupMainLine;
    private RadioButton radBtnMainLine1;
    private RadioButton radBtnMainLine2;
    private RadioButton radBtnMainLine3;
    private RadioButton radBtnMainLine4;
    private Button btn_main_create;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        radGupCarType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton = findViewById(checkedId);
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        radGupMainLine.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton = findViewById(checkedId);
                Log.i("RadioButton", radioButton.getText().toString());

            }
        });

        btn_main_create.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String msg = "";
                int carId = radGupCarType.getCheckedRadioButtonId();
                if (carId != -1) {
                    msg = ((RadioButton) findViewById(carId)).getText().toString();
                }else{
                    msg="未选车型";
            }
                Log.i("点击按钮",msg);
                int lindId =radGupMainLine.getCheckedRadioButtonId();
                if (carId != -1) {
                    msg+="，"+((RadioButton) findViewById(lindId)).getText().toString();
                }else {
                    msg = "未选生产线";
                }
                    Log.i("点击按钮", msg);
                }
        });

    }

    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        radGupCarType = (RadioGroup) findViewById(R.id.radGup_car_type);
        radBtnMainSaloon = (RadioButton) findViewById(R.id.radBtn_main_saloon);
        radBtnMainMPV = (RadioButton) findViewById(R.id.radBtn_main_MPV);
        radBtnMainSUV = (RadioButton) findViewById(R.id.radBtn_main_SUV);
        radGupMainLine = (RadioGroup) findViewById(R.id.radGup_main_line);
        radBtnMainLine1 = (RadioButton) findViewById(R.id.radBtn_main_line1);
        radBtnMainLine2 = (RadioButton) findViewById(R.id.radBtn_main_line2);
        radBtnMainLine3 = (RadioButton) findViewById(R.id.radBtn_main_line3);
        radBtnMainLine4 = (RadioButton) findViewById(R.id.radBtn_main_line4);
        btn_main_create = (Button) findViewById(R.id.btn_main_create);
    }
}